package homeWorks;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Scanner;

public class UserDemo {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入用户信息:");
        System.out.print("姓名:");
        String name = scan.nextLine();
        System.out.print("密码:");
        String pwd = scan.nextLine();
        System.out.print("昵称:");
        String nick = scan.nextLine();
        System.out.print("年龄:");
        int age = scan.nextInt();

        User user = new User(name, pwd, nick, age);
        try (ObjectOutputStream oos = new ObjectOutputStream(
                new FileOutputStream(name + ".obj"));
        ) {
            oos.writeObject(user);
            System.out.println("写出完毕!");
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
